﻿#include "stdafx.h"
#include "XFontIntParserFilter.h"

#include "XBSTR.h"
#include "XString.h"
#include "StrUtil.h"
#include "Util.h"
#include "IXFont.h"

#include "ParseHelper.h"


CXFontIntParserFilter::CXFontIntParserFilter()
{
    ;
}

CXFontIntParserFilter::~CXFontIntParserFilter()
{
    ;
}

// 填充属性
BOOL CXFontIntParserFilter::FillAttr(IN IXConfigNode* pNode, IN IXControl* pControl, IN IXControl* pParent)
{
    XBSTR bstrTemp;
    LONG lTemp;
    HRESULT hResult;
    BOOL bTemp;

    IXFont* pFont = NULL;
    pControl->get_Font(&pFont);
    if(pFont == NULL)
        Util::CreateObject(&pFont);
    if(pFont == NULL)
    {
        XASSERT_ERROR(pFont != NULL, _T("get_Font Failed"));
        return FALSE;
    }

    // FontSize
    hResult = pNode->GetValue(_T("fontsize"), &lTemp);
    if(SUCCEEDED(hResult))
    {
        pFont->put_FontSize(lTemp);
    }

    // Bold
    hResult = pNode->GetValue(_T("bold"), &bTemp);
    if(SUCCEEDED(hResult))
    {
        pFont->put_Bold(bTemp);
    }

    // Italic
    hResult = pNode->GetValue(_T("italic"), &bTemp);
    if(SUCCEEDED(hResult))
    {
        pFont->put_Italic(bTemp);
    }

    // Underline
    hResult = pNode->GetValue(_T("underline"), &bTemp);
    if(SUCCEEDED(hResult))
    {
        pFont->put_Underline(bTemp);
    }

    // StrikeOut
    hResult = pNode->GetValue(_T("strikeout"), &bTemp);
    if(SUCCEEDED(hResult))
    {
        pFont->put_StrikeOut(bTemp);
    }

    // FontName
    hResult = pNode->GetValue(_T("fontname"), &bstrTemp);
    if(SUCCEEDED(hResult))
    {
        pFont->put_FontName(bstrTemp);
    }

    pControl->put_Font(pFont);
    if(pControl->IsAutoSize())
        pControl->AutoSize();

    return TRUE;
}
